package com.fcscs.cservice.communication;

import java.io.Serializable;
import java.util.Map;

import org.apache.log4j.Logger;

import com.fcscs.core.system.ApplicationContextHolder;
import com.fcscs.cservice.common.CServiceCommonEnums;
import com.fcscs.cservice.communication.CommIntfAdaptor.CommParam;

public class LocalOutboundHandler implements OutboundHandler {

	private static final Logger LOG = Logger.getLogger(LocalOutboundHandler.class);

	@Override
	public byte[] sendBytes(String ip, CServiceCommonEnums.CommAdaptorEnum commAdaptor, String destination, byte[] data, Map<CommParam, Serializable> params) {
		CommIntfAdaptor adp = (CommIntfAdaptor)ApplicationContextHolder.getBeanFromContext(commAdaptor.getAdaptorName());
		if (adp != null) {
			LOG.debug("--------------transporting data to " + destination);
			adp.transport(data, params);
			LOG.debug("--------------transporting data to " + destination + " successful");
			return data;
		}
		LOG.debug("--------------transporting data to " + destination + " failed");
		return null;
	}
}
